package com.chukun.netty.chat;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.DelimiterBasedFrameDecoder;
import io.netty.handler.codec.Delimiters;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;
import io.netty.util.CharsetUtil;

/**
 * @author chukun
 * 初始化服务端的解码器
 */
public class NettyChartClientChannelInitializer extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        //换行符解码器
        ch.pipeline().addLast("server delimiter codec",new DelimiterBasedFrameDecoder(1024, Delimiters.lineDelimiter()));
        ch.pipeline().addLast("server string decoder",new StringDecoder(CharsetUtil.UTF_8));
        ch.pipeline().addLast("server string encoder",new StringEncoder(CharsetUtil.UTF_8));
        ch.pipeline().addLast("server chat handler",new NettyChatClientHandler());
    }
}
